﻿Public Class frmDepartamento
    Public vectorx1(,) As String
    Public vectorx1D(,) As String
    Dim capID As Integer
    Dim capIDdueño As Integer
    Private Sub frmDepartamento_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try

            datosDepCBBlock()
            datosDepCBGrupoGastos()
            vectorx1 = datosDepCBPersona()
            vectorx1D = datosDepCBPersonaDueño()
            datosDepCBBlockL()
            listaDepartamentos(1)
        Catch ex As Exception
            mensajeError(ex)
        End Try
    End Sub

    Private Sub btnIngresar_Click(sender As Object, e As EventArgs) Handles btnIngresar.Click
        Try
            If txtActual.TextLength = 0 Or cbPersona.SelectedIndex < 0 And cbPersonaD.SelectedIndex < 0 Then

                MessageBox.Show(msjCampoBlanco, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else

                ingresaDepartamento(txtActual.Text, txtAnterior.Text, cbBlock.SelectedValue, capID, cbGrupo.SelectedValue, txtRol.Text, txtNic.Text, txtNicAgua.Text, capIDdueño)
                txtActual.Clear()
                txtAnterior.Clear()
                txtRol.Clear()
                txtNic.Clear()
                txtNicAgua.Clear()
            End If
            

        Catch ex As Exception
            mensajeError(ex)
        End Try
    End Sub

  


    Private Sub cbSelBlock_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbSelBlock.SelectedIndexChanged
        Try
            If IsNumeric(cbSelBlock.SelectedValue) Then
                listaDepartamentos(cbSelBlock.SelectedValue)
            End If
        Catch ex As Exception
            mensajeError(ex)
        End Try

    End Sub



    Private Sub cbPersona_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbPersona.SelectedIndexChanged
        'Captura Id correspondiente a la persona
        capID = CInt(vectorx1(cbPersona.SelectedIndex, 0))
    End Sub

    Private Sub cbPersonaD_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbPersonaD.SelectedIndexChanged
        'Captura Id correspondiente a la persona
        capIDdueño = CInt(vectorx1D(cbPersonaD.SelectedIndex, 0))
    End Sub


  
    Private Sub cbBlock_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbBlock.SelectedIndexChanged
        For Each item As Object In cbSelBlock.Items

            If item(0) = cbBlock.SelectedValue Then
                cbSelBlock.SelectedValue = cbBlock.SelectedValue
           
            End If

        Next


    End Sub

    
  

    Private Sub DGV_Departamentos_Click(sender As Object, e As EventArgs) Handles DGV_Departamentos.Click
        Try
            If IsNumeric(DGV_Departamentos.Item(0, DGV_Departamentos.CurrentCell.RowIndex).Value) Then
                datoDepatamento = DGV_Departamentos.Item(0, DGV_Departamentos.CurrentCell.RowIndex).Value

                frmEditaDepartamento.MdiParent = CType(Me.MdiParent, System.Windows.Forms.Form)
                frmEditaDepartamento.Show()





            End If
        Catch ex As Exception

        End Try
   

        'MsgBox("" + DGV_Departamentos.Item(0, DGV_Departamentos.CurrentCell.RowIndex).Value.ToString)
    End Sub

End Class